package common

import (
	"golang.org/x/net/context"
	"google.golang.org/grpc/metadata"
	"time"
)

// WithTimeoutContext 超时上下文
func WithTimeoutContext(timeout time.Duration) (context.Context, context.CancelFunc) {
	return context.WithTimeout(context.Background(), timeout)
}

// WithMetaDataOutGoingTimeoutContext 超时并且带metadata的context
func WithMetaDataOutGoingTimeoutContext(timeout time.Duration, md metadata.MD) (context.Context, context.CancelFunc) {
	ctx, cancel := context.WithTimeout(context.Background(), timeout)
	return metadata.NewOutgoingContext(ctx, md), cancel
}
